#!/usr/bin/python
import getpass
import sys, time

#sys.setdefaultencoding('utf-8')
sys.path.append("/usr/local/google_appengine")
sys.path.append("../viewer/")

from google.appengine.ext.remote_api import remote_api_stub
from google.appengine.ext import db
import models, constants

def authFunc():
    return raw_input('Username:'), getpass.getpass('Password:')
app_id = "booksmap"
host = '%s.appspot.com' % app_id
remote_api_stub.ConfigureRemoteDatastore(app_id, '/remote_api', authFunc, host)



def removeAll(model):
    ct = 0
    while True:
        try:
            while True:
                ent = model.all()
                remain = ent.count()
                if remain == 0: break
                db.delete(ent.fetch(100))
                time.sleep(0.5)
                print "%d: %d" % (ct, remain)
                ct = ct + 1
        except Exception, e:
            print e
            continue
        break

removeAll(models.Node)
